package com.adnaan.backend.service.impl;

import com.adnaan.backend.entity.HerbalTaboo;
import com.adnaan.backend.mapper.HerbalTabooMapper;
import com.adnaan.backend.service.HerbalTabooService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * author: adnaan
 * create: 2025-02-19 13:09
 * Description:
 */
@Service
public class HerbalTabooServiceImpl extends ServiceImpl<HerbalTabooMapper, HerbalTaboo> implements HerbalTabooService {
    @Override
    public Long addOrSaveTaboo(Long id, String people, String matters) {
        // 创建 HerbalTaboo 实体对象
        HerbalTaboo herbalTaboo = new HerbalTaboo();
        if (id != null) {
            herbalTaboo.setId(id);
        }
        // 设置禁忌人群信息
        herbalTaboo.setContraindicatedPeople(people);
        // 设置禁忌事项信息
        herbalTaboo.setContraindicatedMatters(matters);
        // 调用 saveOrUpdate 方法保存或更新实体对象
        boolean success = this.saveOrUpdate(herbalTaboo);
        if (success) {
            // 如果保存或更新成功，返回实体对象的 id
            return herbalTaboo.getId();
        } else {
            // 如果保存或更新失败，返回 null
            return null;
        }
    }
}
